package com.etop.learnapp.fragment;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;

import com.etop.learnapp.R;
import com.etop.learnapp.activity.ApplyActivity;
import com.etop.learnapp.adapter.Student_Adapter;

import java.util.ArrayList;
import java.util.List;


public class Student_List_Fragment extends Fragment {

    ImageButton btnAddStudent;
    public Button  btnComplete,btn_studentListBack;
    private ListView show;
    private List list = new ArrayList();
    private Student_Adapter myadapter;
    private Context mContext;
    private View view;

    public void init() {
        // 组件
        btnAddStudent = (ImageButton)view.findViewById(R.id.btn_add2);
        btnComplete =(Button)view.findViewById(R.id.btn_complete);
        btn_studentListBack = (Button)view.findViewById(R.id.btn_studentListBack);
        btn_studentListBack.setOnClickListener((ApplyActivity) getActivity());
        btnComplete.setOnClickListener((ApplyActivity) getActivity());
        show = (ListView)view.findViewById(R.id.lv_show);
        // 添加监听器

        btnAddStudent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int i = list.size();
                list.add(i);
                myadapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        ((ApplyActivity)getActivity()).setCurrentPage(3);
        view = inflater.inflate(R.layout.fragment_student__list, container, false);
        return view;
    }

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        init();
        if(list.isEmpty())
            list.add(1);

        myadapter = new Student_Adapter((ApplyActivity)getActivity(), list);
        show.setAdapter(myadapter);
    }
}
